package org.custom.spring.boot.datasource.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.custom.spring.boot.datasource.entity.RestTemplatePropertity;
import org.custom.spring.boot.datasource.entity.StatementPropertity;
import org.custom.spring.boot.datasource.service.CustomService;
import org.custom.spring.boot.datasource.service.RestTemplateService;
import org.custom.spring.boot.entity.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 数据解析相关网络接口
 *
 * @author 李坤
 * @date 2022/3/31 10:53
 */
@RestController
@Api(tags = "数据解析相关网络接口")
@RequestMapping("/data/parse")
public class DataParseController {
    @Resource
    private CustomService customService;
    @Resource
    private RestTemplateService restTemplateService;

    @PostMapping("/sql")
    @ApiOperation(value = "SQL数据解析接口")
    public Result<List<Map<String, Object>>> dataParseSql(@RequestBody @Validated StatementPropertity statementPropertity) {
        return Result.success(customService.executeCustomSql(statementPropertity));
    }

    @PostMapping("/api")
    @ApiOperation(value = "网络接口数据解析接口")
    public Result<Map<String, Object>> dataParse4Api(@RequestBody @Validated RestTemplatePropertity templatePropertity) {
        return Result.success(restTemplateService.executeRequest(templatePropertity));
    }
}
